//---------------------------------------------------------------------------
#include <vcl.h>
#include "shellapi.h"
#pragma hdrstop

#include "DropListBox.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck は、定義されたコンポーネントが純粋仮想関数を含む
// 抽象クラスではないことを確認するために定義されています。
//

static inline void ValidCtrCheck(TDropListBox *)
{
        new TDropListBox(NULL);
}
//---------------------------------------------------------------------------
__fastcall TDropListBox::TDropListBox(TComponent* Owner)
        : TListBox(Owner)
{
    mfAccept = false;
}
//---------------------------------------------------------------------------
bool __fastcall TDropListBox::GetDropAccept(void)
{
    return mfAccept;
}
//---------------------------------------------------------------------------
void __fastcall TDropListBox::SetDropAccept(bool fAccept)
{
    ::DragAcceptFiles(Handle, fAccept);
    mfAccept = fAccept;
}
//---------------------------------------------------------------------------
void __fastcall TDropListBox::WMDropFiles(TWMDropFiles Msg)
{

    // オブジェクトインスペクタでは無視
    if (ComponentState.Contains(csDesigning)) {
        return;
    }

    int DFiles = DragQueryFile((HDROP)Msg.Drop, 0xffffffff, (LPSTR) NULL,255);
    TStringList *FileNames = new TStringList;
    char theFileName[256];
    for (int i=0; i < DFiles; i++) {
    	::DragQueryFile((HDROP)Msg.Drop, i, theFileName, 256);
        FileNames->Add(theFileName);
    }
    if (FOnDropFiles != NULL) {
        try {
          FOnDropFiles(this, FileNames);
        } catch(...) {
           Application->HandleException(NULL);
        }
    }
    ::DragFinish((HDROP)Msg.Drop);
    delete FileNames;
}
//---------------------------------------------------------------------------
namespace Droplistbox
{
        void __fastcall PACKAGE Register()
        {
                 TComponentClass classes[1] = {__classid(TDropListBox)};
                 RegisterComponents("43T", classes, 0);
        }
}
//---------------------------------------------------------------------------
 